package com.github.qingcheng.controller;

import com.github.qingcheng.pojo.Brand;
import com.github.qingcheng.pojo.PageResult;
import com.github.qingcheng.pojo.Result;
import com.github.qingcheng.service.BrandService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌控制层
 * @author GY
 * @version V1.0
 * @date 2025-01-21 08:43
 */
@Slf4j
@RequestMapping("/brand")
@RestController
@RequiredArgsConstructor
public class BrandController {
    private final BrandService brandService;

    /**
     * 分页条件查询
     */
    @PostMapping("/page")
    public PageResult findPage(@RequestParam("page") Integer page,@RequestParam("size") Integer size,@RequestBody Brand brand){
        log.info("BrandController-findPage-brand:{}",brand);
        brand.setPage(page);
        brand.setSize(size);
        PageResult pageResult = brandService.findPage(brand);
        return pageResult;
    }

    /**
     *新增品牌
     */
    @PostMapping("/add")
    public Result add(@RequestBody Brand brand){
        log.info("BrandController-add-brand:{}",brand);
        brandService.add(brand);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("delete/{id}")
    private Result delete(@PathVariable Integer id){
        log.info("BrandController-delete-id:{}",id);
        brandService.delete(id);
        return Result.success();
    }

    /**
     * 根据ID查询信息
     */
    @GetMapping("/{id}")
    public Result findById(@ PathVariable("id" ) Integer id){
        log.info("BrandController-findById-id:{}",id);
        Brand brand =brandService.findById(id);
        return Result.success(brand);
    }

    /**
     * 修改信息
     */
    @PutMapping("/update")
    public Result update(@RequestBody Brand brand){
        log.info("BrandController-update-brand:{}",brand);
        brandService.update(brand);
        return Result.success();
    }



















}
